<?php 

function list_img_files($path){
	$dir = $_SERVER['DOCUMENT_ROOT'] . "/uploads/images";
	$type = array("gif", "jpg", "jpeg", "png");
	
	$res = "<script>var image_list = '";
	// Open a known directory, and proceed to read its contents
	if (is_dir($dir)) {
	    if ($dh = opendir($dir)) {
	        while (($file = readdir($dh)) !== false) {
	        	$pieces = explode('.', $file);
	        	if (in_array($pieces[1], $type))
	            	$res .= "$file,";
	        }
	        closedir($dh);
	        
	        //if ($res[strlen($res) - 1] == ',') 
	        //	$res = substr($res, 0, strlen($res) - 1); // remove last comma
	        $res .= "'</script>";
	    }
	}
	else $res = $dir;
	
	return $res;
}